// signPackage/pages/leader_sale/leader_sale.js
var common = require("../../../common/common.js").common;

var app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        nav: [ {
            id: 1,
            text: "日榜"
        }, {
            id: 2,
            text: "周榜"
        }, {
            id: 3,
            text: "月榜"
        }, {
            id: 4,
            text: "年榜"
        } ],
        choose_nav: 1,
        cli_proList: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.getBase();
        this.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        this.getLeaderProduct();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    //全局基础配置信息
    getBase: function() {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: res.extra.color_main
                });
                var leaderName = res.extra.leader_title ? res.extra.leader_title : "团长";
                wx.setNavigationBarTitle({
                    title: `${leaderName}销量排行`
                });
                that.setData({
                    color_main: res.extra.color_main,
                    apptitle: res.extra.title,
                    style: res.extra.style,
                    timeStyle: {
                        height: 32,
                        mainColor: res.extra.color_main
                    }
                });
            }
        });
    },
    choose_nav: function(e) {
        var id = e.currentTarget.dataset.id;
        console.log(id);
        var that = this;
        this.setData({
            choose_nav: id
        });
        this.getLeaderProduct();
    },
    getLeaderProduct() {
        var that = this;
        var id = that.data.goodsId;
        common.request({
            endpoint: "leader/cli_product",
            method: "post",
            data: {
                day: that.data.choose_nav
            },
            success: res => {
                let delayList = res.extra.slice(3);
                let appList = res.extra.slice(0, 3);
                that.setData({
                    appList: appList,
                    delayList: delayList
                });
            }
        });
    }
});